home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / digsby / digsbybuddy.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  5KB  |  144 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from jabber import jbuddy, jabber_util
  5. from util import Timer, callsback
  6. from common import pref, profile
  7. from common.actions import action
  8. from objects import ip, pagetime
  9. jbuddy_caps = jbuddy.caps
  10. import logging
  11. log = logging.getLogger('digsby.buddy')
  12.  
  13. def no_widgets(self, *a, **k):
  14.     return not (self.iswidget)
  15.  
  16.  
  17. class DigsbyBuddy(jbuddy):
  18.     
  19.     def __init__(self, jabber_, jid, rosteritem = None):
  20.         jbuddy.__init__(self, jabber_, jid, rosteritem)
  21.         iswidget = iswidget
  22.         import digsby.widgets.widget
  23.         self.iswidget = iswidget(self)
  24.         self.ip = None
  25.         self.online_time = None
  26.         profile.account_manager.buddywatcher.unregister(self)
  27.  
  28.     
  29.     def is_video_widget(self):
  30.         node = self.jid.node
  31.         if node:
  32.             pass
  33.         return node.startswith('video.')
  34.  
  35.     is_video_widget = property(is_video_widget)
  36.     
  37.     def remove(self, callback = None):
  38.         if self.iswidget:
  39.             return callback.success()
  40.         
  41.         return jbuddy.remove(self, callback = callback)
  42.  
  43.     remove = action(no_widgets)(callsback(remove))
  44.     
  45.     def caps(self):
  46.         cs = []
  47.         caps = caps
  48.         import common
  49.         if self.id in self.protocol.bots:
  50.             cs.append(caps.BOT)
  51.         
  52.         if self.iswidget:
  53.             cs.extend([
  54.                 caps.INFO,
  55.                 caps.IM])
  56.         else:
  57.             cs.extend(jbuddy.get_caps(self))
  58.         return cs
  59.  
  60.     caps = property(caps)
  61.     
  62.     def service(self):
  63.         return 'digsby'
  64.  
  65.     service = property(service)
  66.     
  67.     def serviceicon(self):
  68.         skin = skin
  69.         import gui
  70.         return None if not self.iswidget else skin.get('serviceicons.widget')
  71.  
  72.     serviceicon = property(serviceicon)
  73.     
  74.     def update_presence(self, presence, buddy = None):
  75.         groups = jabber_util.xpath_eval(presence.xmlnode, 'd:group', {
  76.             'd': 'digsby:setgroup' })
  77.         if groups:
  78.             self.widget_to_group(groups[0].getContent())
  79.         
  80.         ips = jabber_util.xpath_eval(presence.xmlnode, 'i:ip', {
  81.             'i': ip.IP_NS })
  82.         if ips:
  83.             
  84.             try:
  85.                 self.ip = ip.Ip(ips[0]).ip
  86.  
  87.         
  88.         pagetimes = jabber_util.xpath_eval(presence.xmlnode, 'p:pagetime', {
  89.             'p': pagetime.PAGETIME_NS })
  90.         if pagetimes:
  91.             
  92.             try:
  93.                 self.online_time = pagetime.PageTime(pagetimes[0]).pagetime / 1000
  94.  
  95.         
  96.         jbuddy.update_presence(self, presence, buddy = buddy)
  97.  
  98.     
  99.     def widget_to_group(self, groupname, callback = None):
  100.         log.info('%s add_to_group %s', self, groupname)
  101.         pending = self.pending_adds
  102.         if groupname in pending:
  103.             log.info('ignoring request.')
  104.         else:
  105.             pending.add(groupname)
  106.         item = self.protocol.roster.get_item_by_jid(self.id).clone()
  107.         if groupname not in item.groups:
  108.             item.groups[:] = [
  109.                 groupname]
  110.             query = item.make_roster_push()
  111.             
  112.             def onsuccess(_s):
  113.                 pending.discard(groupname)
  114.                 callback.success()
  115.  
  116.             
  117.             def onerror(_s = (None, None, (None, None, None), None)):
  118.                 pending.discard(groupname)
  119.                 log.warning('error adding %r to %s', self.id, groupname)
  120.                 callback.error()
  121.  
  122.             self.protocol.send_cb(query, success = onsuccess, error = onerror, timeout = onerror)
  123.         
  124.  
  125.     widget_to_group = action(needs = ((unicode, 'Group name'),))(callsback(widget_to_group))
  126.     icon_disabled = property((lambda : True), (lambda : pass))
  127.     
  128.     def __repr__(self):
  129.         
  130.         try:
  131.             res = len(self.resources)
  132.         except:
  133.             res = 0
  134.  
  135.         
  136.         try:
  137.             n = self.name
  138.         except:
  139.             n = ''
  140.  
  141.         return '<DigsbyBuddy %s %d>' % (n, res)
  142.  
  143.  
  144.